<?php

class Member_yongjinController extends Member {
    public $yongjin;
    public function __construct() {
		parent::__construct();
		$this->yongjin = $this->model('yongjin');
		
		if(!get_cookie('openid')){
		 $this->oauthlogin();//微信授权跟获取
		}
		
	}
	
	public function indexAction() {
		$member_id = get_cookie('yuangong_id');//判断是否已经登录
		if(empty($member_id)){
			$back = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : url('member/');
			$this->redirect(url('member/', array('back' => urlencode($back))));
		}
		$type = get_cookie('type');
		if($type){
			$this->redirect(url('member/'));
		}
		$member = $this->db->where('id',$member_id)->get('member')->row_array();
		//print_r($member);
		$where = '1=1 and j.parentid='.$member_id;
		
		$page = (int)$this->get('page') ? (int)$this->get('page') : 1;
	    //$pagesize = isset($this->site['SITE_ADMIN_PAGESIZE']) && $this->site['SITE_ADMIN_PAGESIZE'] ? $this->site['SITE_ADMIN_PAGESIZE'] : 8;
		$pagesize = 10;
		
	    $urlparam = array('page' => '{page}');
		$order = 'j.id desc';
		$limit = ($page-1)*$pagesize.",$pagesize";
		
		$data =  $this->yongjin->get_all_list($where,$order ,$limit); //列表
		//print_r($data);
		$total = $this->yongjin->get_all_list($where,$order ,$limit,true); //统计数量	

		$count = array();	//统计各个状态的数据量
	    $pagelist = $this->instance('pagelist');	//加载分页类
		$pagelist->loadconfig();
		$pagelist = $pagelist->total($total)->url(url('member/member_yongjin/', $urlparam))->num($pagesize)->page($page)->output();
		$backurl = $this->get('back') ? $this->get('back') : (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : url('member/'));
		$pagenum = ceil($total/$pagesize);
		
		$xxxf = isset($this->site['SITE_ADMIN_XIAOFEI']) && $this->site['SITE_ADMIN_XIAOFEI'] ? $this->site['SITE_ADMIN_XIAOFEI'] : 1;//下线消费奖励规则
		$xxdg = isset($this->site['SITE_ADMIN_JIANGLI']) && $this->site['SITE_ADMIN_KECHENG'] ? $this->site['SITE_ADMIN_KECHENG'] : 1;//下线订购课程奖励规则
		
		
		$this->view->assign(array(
			'indexc' => 'yongjin',
			'member' => $member,
			'xxxf' => $xxxf,
			'xxdg' => $xxdg,
			'pagenum' => $pagenum,
			'meta_title' => lang('奖励明细'),
	        'page' => $page,
	        'list' => $data,
			'total' => $total,
	        'pagelist' => $pagelist
	    ));
		$this->view->display('member/member_yongjin');
	}
	
	
	
}